﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit;
using NUnit.Framework;
using wne.Context;
using wne.models;


namespace wne.Tests
{
    [TestFixture]
    class qqq
    {
        [Test]
        public void UasyaTest1()
        {
            var acfacade = new core.AccountFacadeSql();
            var adfacade = new core.AdminFacadeSql();
            Assert.AreEqual(acfacade.IsValidUserPass("user", "pass"), false);
            Assert.AreEqual(acfacade.IsValidUserPass("q", "q"), true);
            models.GroupModel g=new GroupModel();
            g.Id = 1009;
            g.Name = "www";
            //adfacade.RemoveGroup(1010);
            //Assert.AreEqual(adfacade.AddGroup("g2"),1010);
            g.SelectedParents.Add(1010,"g2");
            FieldModel fieldModel=new FieldModel();
            fieldModel.FieldId = 0;
            fieldModel.Mandatory = false;
            fieldModel.Type = (FieldTypeEnum)1;
            fieldModel.UserCanEdit = true;
            fieldModel.Name = "field1";
            UserModel user = new UserModel()
            {
                FirstName = "q",
                Id = 0,
                SecondName = "w",
                Phone = "777",
                Surname = "e",
                UserBd = "01.01.1999",
                UserEmail = "@",
                UserGroups = new List<GroupModel>(),
                UserName = "666qwerty"
            };
            g.Fields.Insert(0,fieldModel);
            adfacade.UpdateGroup(g);
            UserModel us=new UserModel();
            us.FirstName = "father";
            us.Phone = "666";
            us.SecondName = "son";
            us.UserBd = "01.01.1999";
            us.UserEmail = "@mail.ru";
            us.UserName = "Iegova";
            us.Surname = "sn_spirit";
            us.UserGroups=new List<GroupModel>();
            us.UserGroups.Add(g);
            us.Id = adfacade.AddUser(us);
            adfacade.RemoveUser((int)us.Id);
            //GroupModel gm=adfacade.GetGroupById(1009);
            //adfacade.UpdateGroup(gm);
        }

        [Test]
        public void Test2()
        {
            
            using (var context = new tpksEntities())
            {
                var allusers = context.User.ToList();
                var allgroups = context.Group.ToList();

                Console.WriteLine(context.User.Include("Group").Where(x=>x.User_ID==42).ToString());
                Console.WriteLine("----------------------");
                Console.WriteLine(context.User.Where(x=>x.User_ID==42).Include("Group"));
                Console.WriteLine("------------------");
                Console.WriteLine(context.User.Where(x => x.User_ID == 42).ToString());
                Console.WriteLine(context.Group.Include("Group_Field").ToString());
            }
        }
    }
}
